<?
require_once('config.php');
$action = getValue('action','str','POST');
if($action == 'submit'){
   $mod_name = getValue('mod_name','str','POST');
   $mod_fullname = getValue('mod_fullname','str','POST');
   $mod_pathname = getValue('mod_pathname','str','POST');
   $mod_order = getValue('mod_order','int','POST');
   $mod_filename = getValue('mod_filename','str','POST');
   $db_exe = new db_execute( $sql = "INSERT INTO moduols(
                                          mod_name,
                                          mod_fullname,
                                          mod_pathname,
                                          mod_order,
                                          mod_filename,
                                          mod_status
                                       )
                                       VALUES(
                                          '" . $mod_name . "',
                                          '" . $mod_fullname . "',
                                          '" . $mod_pathname . "',
                                          " . $mod_order . ",
                                          '" . $mod_filename . "',
                                          1)" );
   $path_to_folder = PATH_ROOT.'/cms/modules/'.$mod_name;
   //echo $path_to_folder
   if(!is_dir($path_to_folder)){
      mkdir($path_to_folder,7705);
   }
   $array_file = explode('|',$mod_pathname);
   if(count($array_file) > 0){
      foreach($array_file as $value){
         file_put_contents($path_to_folder.'/'.$value,'<?php ?>');
      }
   }
   echo '<span style="color: #01B42C;font-size: 14px;font-weight: bold;">Thêm thành công</span>';
}
$total = $module->getTotal();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Thêm mới <?=$moduol_name?></title>
   <?=$css_global?>
   <?=$js_global?>
   <script>
     $(function() {
       $( "#datepicker" ).datepicker();
       $(document).on('click','.reload_tab' ,function(){
         window.location.reload();
       });
     });
  </script>
</head>
<div class="row-fluid">
   <div class="head">
      <div class="isw-grid"></div>
      <h1>Thêm mới <?=$moduol_name?></h1>      
      <div class="reload_tab" title="Reload"></div>                         
      <div class="clear"></div>
   </div>
   <div class="block-fluid">
      <form class="form-horizontal" name="add" action="" method="POST" enctype="multipart/form-data"  onsubmit="">
         <input type="hidden" name="action" value="submit" />
         <fieldset>
            <div class="control-group">
               <label class="control-label" >Tên thư mục</label>
               <div class="controls">
						<input type="text" class="input-xlarge tooltip-right span3" id="mod_name" name="mod_name" title="Tên thư mục"/>
					</div>
            </div>
            <div class="control-group">
               <label class="control-label" >Tên module</label>
               <div class="controls">
                  <input type="text" class="input-xlarge tooltip-right span3" id="mod_fullname" name="mod_fullname" title="Tên module" />
					</div>
            </div>
            <div class="control-group">
               <label class="control-label" >Tên file</label>
               <div class="controls">
						<input type="text" class="input-xlarge tooltip-right span3" id="mod_pathname" name="mod_pathname" placeholder="list.php|add.php" title="Phân cách nhau bơi dấu |"/>
					</div>
            </div>
            <div class="control-group">
               <label class="control-label" >Vị trí</label>
               <div class="controls">
                  
						<select id="mod_order" class="span3" name="mod_order">
                     <option value="1">Đầu tiên</option>
                     <?if($total > 1):?>
                        <?for($i = 2;$i <= $total; $i++):?>
                           <option value="<?=$i?>"><?=$i?></option>
                        <?endfor?>
                        <option value="<?=$total+1?>"> Cuối cùng</option>
                     <?endif?>
                  </select>
					</div>
            </div>
            <div class="control-group">
					<label class="control-label" >Sub module</label>
               <div class="controls">
						<input type="text" class="input-xlarge tooltip-right span3" id="mod_filename" name="mod_filename" placeholder="Danh sách|Thêm mới" title="Tên module con"/>
					</div>
				</div>
            
            <div class="form-actions">
					<button type="submit" class="btn btn-info">Thêm mới</button>
					<button type="reset"  class="btn btn-warning">Làm lại</button>
				</div>
         </fieldset>
      </form>
   </div> 
</div>